<?php
namespace Home\Controller;
use Think\Controller;
use Think\Page;

class IndexController extends Controller{
    public function index(){
        $o = M("info");
        $rs = $o->where('infoclass=3')->limit(8)->select();
        $this->assign('rs',$rs);

        $xw = $o->where('infoclass=2')->limit(5)->select();
        $this->assign('xw',$xw);
        #获取导航栏信息
        $obj = M("class");
        $data = $obj->select();
        //$menu = $db->getMoreData("select #from class order by classSort asc");
        $this->assign('data',$data);
        
        $this->display();
    }
     function lista(){

        #获取所在位置
        $s = M("class");
       
        $data = $s->select();
       

        //$menu = $db->getMoreData("select #from class order by classSort asc");
        $this->assign('data',$data);
        #接收栏目id
        $classid = isset($_GET['classId']) ? $_GET['classId'] : 1;
        #分页操作
       
        #获取对应栏目数据
        // $rs = $o->where('infoclass ="'.$classid.'"')->select();//所有数据的查询
        //sql语句的拼接 重点
        // $count = $o->where('infoclass ="'.$classid.'"')->count();
        // print_r($count);
        // $pagesize = 10;
        // $pagecount = ceil($count/$pagesize);//去最大整数值
        // print_r($pagecount);
        // $Page       = new \Think\Page($count,5);
        // $show       = $Page->show();// 分页显示输出
        // $this->assign('page',$show);
        
        #page类和limit方法
        $o = M("info");

        $xw = $o->where('infoclass=2')->limit(5)->select();
        $this->assign('xw',$xw);

        $count = $o->where('infoclass ="'.$classid.'"')->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $o->where('infoclass ="'.$classid.'"')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);//赋值分页输出
        
        
        $this->assign('rs',$rs);
       
        $this->display('lista');
    }
    public function details(){
        $infocount = intval($_GET['infocount'])+1;
        $infoid = isset($_GET['infoid']) ? $_GET['infoid'] : '';
        $da['infoCount'] = $infocount;
        // print_r($da);
        #获取导航栏信息
        $s = M("class");
        $data = $s->select();
        //$menu = $db->getMoreData("select #from class order by classSort asc");
        $this->assign('data',$data);
      
        $o = M("info");
        $o->where('infoid="'.$infoid.'"')->save($da);

        $xw = $o->where('infoclass=2')->limit(5)->select();
        $this->assign('xw',$xw);

        $infoid = isset($_GET['infoid']) ? $_GET['infoid'] : 1;//获取url的参数
        $rs = $o->where('infoid ="'.$infoid.'"')->find();//sql语句的拼接
        $this->assign('rs',$rs);
        $this->display();
    }
    
}